1
/****************************** Module Header ******************************\
2 * Module Name: TPHClass.cs
3 * Project: CSEFEntityDataModel
4 * Copyright (c) Microsoft Corporation.
6 * This example demonstrates how to establish table per hierarchy inheritance.
7 * A table-per-type model is a way to model inheritance where each entity is
8 * mapped to a distinct table in the store. Then it shows how to query a list
9 * of people, get the corresponding properties of Person, Student and
12 * This source is subject to the Microsoft Public License.
13 * See http://www.microsoft.com/opensource/licenses.mspx#Ms-PL.
14 * All other rights reserved.
16 * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND,
17 * EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR PURPOSE.
19 \***************************************************************************/
21 #region Using directives
23 using System
.Collections
.Generic
;
29 namespace CSEFEntityDataModel
.TablePerHierarchy
31 public static class TPHClass
33 // Test the query method in TPHClass
34 public static void TPHTest()
39 // Query a list of people, print out the properties of Person,
40 // Student and BusinessStudent
41 public static void Query()
43 using (EFTPHEntities context
= new EFTPHEntities())
45 var people
= from p
in context
.People
48 foreach (var p
in people
)
50 Console
.WriteLine("Student {0} {1}",
56 Console
.WriteLine("EnrollmentDate: {0}",
57 ((Student
)p
).EnrollmentDate
);
59 if (p
is BusinessStudent
)
61 Console
.WriteLine("BusinessCredits: {0}",
62 ((BusinessStudent
)p
).BusinessCredits
);